package com.anyou.mall.goo.goods.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import com.anyou.mall.goo.goods.domain.GooGoods;
import com.anyou.mall.goo.goods.dto.GoodsOperationDTO;
import com.anyou.mall.goo.goods.dto.GoodsSearchParams;
import com.anyou.mall.goo.goods.vo.GoodsVO;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.anyou.common.annotation.Log;
import com.anyou.common.core.controller.BaseController;
import com.anyou.common.core.domain.ApiResult;
import com.anyou.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.anyou.mall.goo.goods.service.ILiGoodsService;
import com.anyou.common.utils.poi.ExcelUtil;
import com.anyou.common.core.page.TableDataInfo;

/**
 * goodsController
 *
 * @author xiaQ
 * @date 2023-09-15
 */
@Api(tags = "goods商品重构-xiaQ")
@RestController
@RequestMapping("/goo/goods")
public class LiGoodsController extends BaseController
{
    @Autowired
    private ILiGoodsService liGoodsService;

    /**
     * 查询goods列表
     */
    @ApiOperation("查询goods列表")
    @PreAuthorize("@ss.hasPermi('goo:goods:list')")
    @GetMapping("/list")
    public TableDataInfo<List<GooGoods>> list(GoodsSearchParams goodsSearchParams)
    {
        startPage();
        List<GooGoods> list = liGoodsService.selectLiGoodsList(goodsSearchParams);
        return getDataTable(list);
    }

    /**
     * 导出goods列表
     */
    /*@ApiOperation("导出goods列表")
    @PreAuthorize("@ss.hasPermi('goo:goods:export')")
    @Log(title = "goods", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LiGoods liGoods)
    {
        List<LiGoods> list = liGoodsService.selectLiGoodsList(liGoods);
        ExcelUtil<LiGoods> util = new ExcelUtil<LiGoods>(LiGoods.class);
        util.exportExcel(response, list, "goods数据");
    }*/

    /**
     * 获取goods详细信息
     */
    @ApiOperation("获取goods详细信息")
    @PreAuthorize("@ss.hasPermi('goo:goods:query')")
    @GetMapping(value = "/get/{id}")
    public ApiResult<GoodsVO> getInfo(@PathVariable("id") Long id)
    {
        return ApiResult.success(liGoodsService.selectLiGoodsById(id));
    }

    /**
     * 新增goods
     */
    @ApiOperation("新增goods")
    @PreAuthorize("@ss.hasPermi('goo:goods:add')")
    @Log(title = "goods", businessType = BusinessType.INSERT)
    @PostMapping(value = "/create", consumes = "application/json", produces = "application/json")
    public ApiResult add(@Valid @RequestBody GoodsOperationDTO goodsOperationDTO)
    {
        return ApiResult.success(liGoodsService.insertLiGoods(goodsOperationDTO));
    }

    /**
     * 修改goods
     */
    @ApiOperation("修改goods")
    @PreAuthorize("@ss.hasPermi('goo:goods:edit')")
    @Log(title = "goods", businessType = BusinessType.UPDATE)
    @PutMapping(value = "/update", consumes = "application/json", produces = "application/json")
    public ApiResult edit(@RequestBody GoodsOperationDTO goodsOperationDTO)
    {
        return ApiResult.success(liGoodsService.updateLiGoods(goodsOperationDTO));
    }

    /**
     * 上下架商品
     */
    /*@ApiOperation("上下架商品")
    @PreAuthorize("@ss.hasPermi('goo:goods:upAndDownGoods')")
    @Log(title = "upAndDownGoods", businessType = BusinessType.UPDATE)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodsId", value = "商品ID", required = true, paramType = "query", allowMultiple = true),
            @ApiImplicitParam(name = "GoodsStatusEnum", value = "上架状态（0上架 1下架）", required = true, paramType = "query")
    })
    @PostMapping(value = "/upAndDown", consumes = "application/json", produces = "application/json")
    public ApiResult upAndDownGoods(@RequestParam List<String> goodsId,@RequestParam String goodsStatusEnum)
    {
        return ApiResult.success(liGoodsService.upAndDownGoods(goodsId,goodsStatusEnum));
    }*/

    /**
     * 删除goods
     */
    /*@ApiOperation("删除goods")
    @PreAuthorize("@ss.hasPermi('goo:goods:remove')")
    @Log(title = "goods", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public ApiResult remove(@PathVariable Long[] ids)
    {
        return ApiResult.success(liGoodsService.deleteLiGoodsByIds(ids));
    }*/
}
